KISSY.use("node",function(S,Node){ 
var location = {
	href:function(uri){
		location.href==uri;
	}
}
$(".add").on("click",function(){
	location.href=("/?a=event_step1&m=shop&c=event");
});
$(".bui-tab-item").on("click",function(){
		$(".bui-tab-item").removeClass("bui-tab-item-selected");
		$(this).addClass("bui-tab-item-selected");
		var tp = $(this).attr("data-tp");
		var admin = $(this).attr("data-admin");
		var sid = $(this).attr("data-sid");
		var type = $(".type").val();
		if(admin=="home"){
		location.href=("/?m=home&c=event&ctp="+tp+(type?"&type="+type:"")+(sid?"&sid="+sid:""));
		}else if(admin=="recom"){
		location.href=("/?m=home&c=event&a=recommend&ctp="+tp+(type?"&type="+type:"")+(sid?"&sid="+sid:""));
		}else if(admin=="user"){
		location.href=("/?m=user&a=events&ctp="+tp+(type?"&type="+type:"")+(sid?"&sid="+sid:""));
		}else{
		location.href=("/?m=shop&c=event&ctp="+tp+(type?"&type="+type:"")+(sid?"&sid="+sid:""));
		}
	});
$(".trash").on("click",function(){
	var ctp =$(this).attr("data-ctp");
	var adm =$(this).attr("data-admin");
	location.href=("/?m="+adm+"&c=event&ctp="+(ctp?ctp:"eggs")+"&type=9");
});
$(".delev,.undelev").on("click",function(){
	var eid = $(this).attr("data-eid");
	var ac = $(this).attr("data-ac");
	if(ac=="del"){
		var msg = "删除";
	}else{
		var msg = "恢复";
	}
	KISSY.io({
		url: "/?a=del_event&m=home&c=event",
		data: {"eid":eid,"ac":ac},
		success: function(data, textStatus) {
			if(data.status==false){
				showDialog(msg+"活动",msg+"失败。。。","row");
			}else{
				showDialog(msg+"活动",msg+"成功！","row");
			}
			$(".reall"+eid).remove();
		},
		complete: function(data){
			
		},
		error: function(){
			alert('error');
		},
		dataType:"jsonp"
	});
});
$(".list").on("click",function(){
	var ctp =$(this).attr("data-ctp");
	var adm =$(this).attr("data-admin");
	location.href=("/?m="+adm+"&c=event&ctp="+(ctp?ctp:"eggs"));
});
$('.js-search').on("click",function(){
	var str = $('.js-sinput').val();
	if(!isNull(str)&&IsInteger(str)){
		location.href=("/?m=home&c=event&sid="+str);
	}else{
		alert("仅能填入店铺ID搜索。");
	}
});
$(".qxtj").on("click",function(){
	var rid=$(this).attr("data-rid");
	var eid=$(this).attr("data-eid");
	KISSY.io({
		url: "/?a=del_recom&m=home&c=event",
		data: {"rid":rid},
		success: function(data, textStatus) {
			if(data.status==false){
				showDialog("推荐活动","取消推荐失败。。。"+data.msg,"row");
			}else{
				showDialog("推荐活动","取消推荐成功！"+data.msg,"row");
				$(".refirst"+eid).remove();
			}
		},
		complete: function(data){
			
		},
		error: function(){
			alert('error');
		},
		dataType:"jsonp"
	});
});
$(".button-primary").on("click",function(){
	var eid=$(this).attr("data-eid");
	var wkn = new Array();
	wkn.push($(this).attr("data-thisweek"));
	wkn.push($(this).attr("data-nextweek"));
	wkn.push($(this).attr("data-thirdweek"));
	wkn.push($(this).attr("data-fourthweek"));
	var str='';
	str += ("<div class=\"\">");
	str += ("	<div class=\"controls\">");
	str += ("		<div class=\"well \">");
	str += ("				<div class=\"control-group\">");
	str += ("					<div class=\"controls\">");
	if(wkn.length>0){
	str += ('日期选择：			<select class="input-small js-wk form">');
	str += ('					<option value="0" data-wk="'+wkn[0]+'">本周</option>');
	str += ('					<option value="1" data-wk="'+wkn[1]+'" selected>下周</option>');
	str += ('					<option value="2" data-wk="'+wkn[2]+'">下下周</option>');
	str += ('					<option value="3" data-wk="'+wkn[3]+'">第四周</option>');
	str += ('					</select><span class="js-wkn">'+wkn[1]+'</span>');
	}
	// str += ("<input type=\"text\" class=\"calendar control-text\" style=\"width:150px\"");
	str += ("					</div>");
	str += ("				</div>");
	str += ("				<div class=\"control-group\">");
	str += ("					<div class=\"controls\">");
	str += ("						<label class=\"checkbox helper\" data-tip=\"首页第一屏\" for=\"\" data-tipc=\"1\"><input type=\"radio\" name=\"index\" class=\"first\"  checked=\"checked\" data-post=\"first\">首页第一屏(1)<i class=\"\"></i></label><div class=\"helper1-tip bui-overlay bui-ext-position tips tips-small tips-info tips-no-icon hide\" style=\"top: 828px ; left: 631.5px\"><div class=\"tips-content\">喜欢店铺</div></div>");
	str += ("						<label class=\"checkbox helper\" data-tip=\"添加店铺到淘宝收藏夹\" for=\"\" data-tipc=\"2\"><input type=\"radio\" name=\"index\" class=\"second\"   data-post=\"second\">首页第二屏(2)<i class=\"\"></i></label><div class=\"helper2-tip bui-overlay bui-ext-position tips tips-small tips-info tips-no-icon hide\" style=\"top: 828px ; left: 701.5px\"><div class=\"tips-content\">添加店铺到淘宝收藏夹</div></div>");
	str += ("						<label class=\"checkbox helper\" data-tip=\"关注店铺主账号\" for=\"\" data-tipc=\"3\"><input type=\"radio\" name=\"index\" class=\"third\"  data-post=\"third\">首页第三屏(1)<i class=\"\"></i></label><div class=\"helper3-tip bui-overlay bui-ext-position tips tips-small tips-info tips-no-icon hide\" style=\"top: 828px ; left: 771.5px\"><div class=\"tips-content\">关注店铺主账号</div></div>");
	str += ("						<label class=\"checkbox helper\" data-tip=\"关注店铺主账号\" for=\"\" data-tipc=\"3\"><input type=\"radio\" name=\"index\" class=\"hot\"  data-post=\"hot\">热门活动(8)<i class=\"\"></i></label><div class=\"helper3-tip bui-overlay bui-ext-position tips tips-small tips-info tips-no-icon hide\" style=\"top: 828px ; left: 771.5px\"><div class=\"tips-content\">关注店铺主账号</div></div>");
	str += ("						<label class=\"checkbox helper\" data-tip=\"关注店铺主账号\" for=\"\" data-tipc=\"3\"><input type=\"radio\"name=\"index\" class=\"push\"  data-post=\"push\">掌柜热荐(4)<i class=\"\"></i></label><div class=\"helper3-tip bui-overlay bui-ext-position tips tips-small tips-info tips-no-icon hide\" style=\"top: 828px ; left: 771.5px\"><div class=\"tips-content\">关注店铺主账号</div></div>");
	str += ("					<button class=\"button button-small button-info save\">确认推荐</button>");
	str += ("					</div>");
	str += ("				</div>");
	str += ("		</div>");
	str += ("	</div>");
	str += ("</div>");
	showDialog("推荐活动","将本活动推荐到以下位置："+str,"form-horizontal");
	$(".js-wk").on("change",function(){
		var j = $(this).val();
		$(".js-wkn").text(wkn[j]);
	});
	var cal = new KISSY.Calendar(".calendar", {popup: true, minDate: new Date()});
	cal.on('select', function (e) {
		var selectDate = new Date(e.date); //e.date is string here
		$(".calendar").val(selectDate.getFullYear() + "-" + ((selectDate.getMonth()+1)>=10?(selectDate.getMonth()+1):"0"+(selectDate.getMonth()+1))+"-"+(selectDate.getDate()>=10?selectDate.getDate():"0"+selectDate.getDate())+" "+(selectDate.getHours()>=10?selectDate.getHours():"0"+selectDate.getHours())+":"+(selectDate.getMinutes()>=10?selectDate.getMinutes():"0"+selectDate.getMinutes())+":"+(selectDate.getSeconds()>=10?selectDate.getSeconds():"0"+selectDate.getSeconds()));
		cal.hide();//hide
	});
	$(".cancel").addClass("hide");
	$(".save").on("click",function(){
		var f = $(".first").getDOMNode();
		var s = $(".second").getDOMNode();
		var t = $(".third").getDOMNode();
		var h = $(".hot").getDOMNode();
		var p = $(".push").getDOMNode();
		var wk = $(".js-wk").val();
		if(f.checked==true){
			var place=1;
		}else if(s.checked==true){
			var place=2;
		}else if(t.checked==true){
			var place=3;
		}else if(h.checked==true){
			var place=4;
		}else if(p.checked==true){
			var place=5;
		}
		KISSY.io({
			url: "/?a=recom&m=home&c=event",
			data: {"eid":eid,"place":place,"wk":wk},
			success: function(data, textStatus) {
			closeDialog();
				if(data.status==false){
					showDialog("推荐活动","发布失败。。。"+data.msg,"row");
				}else{
					$(".w"+eid).attr("data-eid",data.id);
					shwDialog("推荐活动","推荐成功！"+data.msg,"row");
				}
			},
			complete: function(data){
				
			},
			error: function(){
				alert('error');
			},
			dataType:"jsonp"
		});
	});
});
$(".js-upto").on("click",function(){
	var eid = $(this).attr("data-eid");
	showDialog("申请上首页","注意：申请上首页，请对照检查《上首页规则》，符合条件的进入审核环节，择优排期。<button class=\"button js-up\">立即申请</button>","form-horizontal");
	$(".js-up").on("click",function(){
		KISSY.io({
			url: "/?a=shangshouye&m=shop",
			data: {"eid":eid},
			success: function(data, textStatus) {
			closeDialog();
					showDialog("申请上首页",data.msg,"form-horizontal");
			},
			complete: function(data){
				
			},
			error: function(){
				alert('error');
			},
			dataType:"jsonp"
		});
	});
});
$(".js-lstbycom").on("click",function(){
	var tp = $(this).attr("data-tp");
	var sid = $(this).attr("data-sid");
	if($(this).hasClass("icon-chevron-down")){
		var lst="com";
	}else{
		var lst="";
	}
	if(tp=="home"){
		location.href=("/?m=home&c=event&lst="+lst);
	}else{
		location.href=("/?m=shop&c=event&lst="+lst);
	}
});

function isNull( str ){
if ( str == "" ) return true;
if(str.length!=0){    
	var reg=/^[ ]+$/;     
	if(str.match(reg)){    
	   return  true;
	}else{
		return false;
	}
}else{
	return true;
} 
		
}
function IsInteger(str)     
{         
        if(str.length!=0){    
			var reg=/^[-+]?\d*$/;     
			if(str.match(reg)){    
			   return  true;
			}else{
				return false;
			}
        }else{
			return false;
		}  
} 
});